package com.ramos.kuaixiao.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.githang.statusbar.StatusBarCompat;
import com.ramos.kuaixiao.R;
import com.ramos.kuaixiao.entity.Customer;
import com.ramos.kuaixiao.utils.StringUtil;

public class ShopSettingActivity extends BaseAllTabActivity implements View.OnClickListener {

    private LinearLayout title_reback;
    private TextView title_text;
    Customer mCustomer;

    TextView title;
    TextView category;
    TextView address;
    TextView contacts;
    TextView inventory;
    TextView uid;

    private RelativeLayout re_home_shop;
    private RelativeLayout re_home_order;
    private RelativeLayout re_home_task;
    private RelativeLayout re_home_my;
    private TextView tv_home_shop;
    private TextView tv_home_order;
    private TextView tv_home_task;
    private TextView tv_home_my;
    private ImageView ib_home_shop;
    private ImageView ib_home_order;
    private ImageView ib_home_task;
    private ImageView ib_home_my;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop_setting);
        StatusBarCompat.setStatusBarColor(this, getResources().getColor(R.color.title), false);
        title_reback = (LinearLayout) findViewById(R.id.title_reback);
        title_reback.setOnClickListener(this);

        title_text = (TextView) findViewById(R.id.title_text);
        title_text.setText("商店设置");

        mCustomer = (Customer) getIntent().getExtras().get("customer");

        title =  (TextView) findViewById(R.id.title);
        category =  (TextView) findViewById(R.id.category);
        address =  (TextView) findViewById(R.id.address);
        address.setOnClickListener(this);
        contacts =  (TextView) findViewById(R.id.phone);
        uid=  (TextView) findViewById(R.id.uid);
        //contacts.setOnClickListener(this);
        inventory =  (TextView) findViewById(R.id.tv_default_inventory);
        inventory.setOnClickListener(this);
        if(!StringUtil.isEmpty(mCustomer.getHouseName())){
            title.setText(mCustomer.getHouseName());
        } else {
            if(!StringUtil.isEmpty(mCustomer.getName())){
                title.setText(mCustomer.getName());
            }
        }
        if(!StringUtil.isEmpty(mCustomer.getShopType())){
            category.setText(mCustomer.getShopType());
        }
        if(!StringUtil.isEmpty(mCustomer.getAddress())){
            address.setText(mCustomer.getAddress());
        }
        if(!StringUtil.isEmpty(mCustomer.getTelephone())){
            contacts.setText(mCustomer.getTelephone());
        }
        if(!StringUtil.isEmpty(mCustomer.getQid()) && !mCustomer.getQid().equals(mCustomer.getId())){
            uid.setText(mCustomer.getQid());
        }
        initTabView();
    }

    private void initTabView() {
        re_home_shop = (RelativeLayout) findViewById(R.id.re_home_shop);
        re_home_order = (RelativeLayout) findViewById(R.id.re_home_order);
        re_home_task = (RelativeLayout) findViewById(R.id.re_home_task);
        re_home_my = (RelativeLayout) findViewById(R.id.re_home_my);
        re_home_shop.setOnClickListener(this);
        re_home_order.setOnClickListener(this);
        re_home_task.setOnClickListener(this);
        re_home_my.setOnClickListener(this);

        ib_home_shop = ((ImageView) findViewById(R.id.ib_home_shop));
        ib_home_order = ((ImageView) findViewById(R.id.ib_home_order));
        ib_home_task = ((ImageView) findViewById(R.id.ib_home_task));
        ib_home_my = ((ImageView) findViewById(R.id.ib_home_my));

        tv_home_shop = ((TextView) findViewById(R.id.tv_home_shop));
        tv_home_order = ((TextView) findViewById(R.id.tv_home_order));
        tv_home_task = ((TextView) findViewById(R.id.tv_home_task));
        tv_home_my = ((TextView) findViewById(R.id.tv_home_my));

        ib_home_shop.setImageResource(R.drawable.tab_infomation_clk);
        tv_home_shop.setTextColor(getResources().getColor(R.color.title));

        ib_home_order.setImageResource(R.drawable.tab_schedule);
        tv_home_order.setTextColor(getResources().getColor(R.color.bottom_tab_unselected));

        ib_home_task.setImageResource(R.drawable.tab_service);
        tv_home_task.setTextColor(getResources().getColor(R.color.bottom_tab_unselected));

        ib_home_my.setImageResource(R.drawable.tab_contacts);
        tv_home_my.setTextColor(getResources().getColor(R.color.bottom_tab_unselected));

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.title_reback:
                finish();
                break;
            case R.id.address:
                //modifyAddress();
                break;
            case R.id.re_home_shop:
                showMain(1);
                break;
            case R.id.re_home_order:
                showMain(2);
                break;
            case R.id.re_home_task:
                showMain(3);
                break;
            case R.id.re_home_my:
                showMain(4);
                break;
            case R.id.tv_default_inventory:
                getInventory();
                break;
            default:
                break;
        }
    }

    private void modifyAddress() {
        Intent intent = new Intent(this, ModifyAddressActivity.class);
        intent.putExtra("customer", mCustomer);
        startActivity(intent);
    }

    private void getInventory() {
        Intent intent = new Intent(this, ShopWarehouseActivity.class);
        intent.putExtra("customer", mCustomer);
        startActivity(intent);
    }
}


